package com.dreamer.domain.socket;

import javax.persistence.Entity;
import java.util.Date;

@Entity
public class ChatGroup {

    private Integer id;//群id

    private String avatar;//群头像

    private String name;//群名字

    private String uids;//群类成员的ID

    private Integer uid;//创始人

    private Date date;//时间

    public ChatGroup(Integer uid,String name,String avatar) {
        this.name = name;
        this.uid = uid;
        addUid(uid,avatar);
        this.date = new Date();
    }

    public ChatGroup(){

    }


   private int countAvatars(){
       String[] list = this.avatar.split("//+");
       return list.length;
   }

    //增加群成员
    public void addUid(Integer uid,String avatar){
        String tem = String.valueOf(uid);
        uids = uids+"+"+tem+"+";
        //头像最多九张
        if(countAvatars()<9){
            this.avatar= this.avatar+"+"+avatar+"+";
        }
    }

    public boolean hasUid(Integer uid){
        String tem = "+"+uid+"+";
        if(uids.indexOf(tem)>-1){
            return true;
        }
        return false;
    }

    //减少群成员
    public void removeUid(Integer uid){
        String tem = String.valueOf(uid);
        uids = uids.replace("+"+tem+"+","+");
    }

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUids() {
        return uids;
    }

    public void setUids(String uids) {
        this.uids = uids;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}
